package com.example.youhuo.antivity

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.example.mvp.MainActivity
import com.example.myapplication.R
import com.example.youhuo.utils.Custom_Dialog
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class Splash_Activity : AppCompatActivity() ,Custom_Dialog.agreeOnClick,Custom_Dialog.disagreeOnClick{

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash)
        var boolean = getSharedPreferences("msg", MODE_PRIVATE).getBoolean("yes", false)
         var intent = Intent(this, MainActivity::class.java)

        if (boolean){
            GlobalScope.launch {
                delay(3000)
                startActivity(intent)
                finish()
            }
        }else{
            initVIew()
        }


    }

    private fun initVIew() {
        var customdialog  = Custom_Dialog(this)
        customdialog.create_Dialog()
        customdialog.getagreeOnClick(this)
        customdialog.getdisagreeOnClick(this)


    }

    override fun agreeOnClickListener() {
        getSharedPreferences("msg", MODE_PRIVATE).edit().putBoolean("yes",true).commit()
        startActivity(Intent(this,MainActivity::class.java))
    }


    override fun disagreeOnClickListener() {

        this.finish()
    }


}